<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" id="num" />
		<input type="button" value="猜吧" onclick="guess()"/>
		<span id="result"></span>
		
		<script type="text/javascript">
			var random = parseInt(Math.random()*100 + 1);
			console.log(random);
			
			function guess() {
				var num = document.getElementById("num").value;
				var resultSpan = document.getElementById("result");
				if (isNaN(num) || num == "") {
					resultSpan.innerHTML = "请输入数字";
					return;
				}
				
				if (num > random) {
					resultSpan.innerHTML = "猜大了";
				} else if(num < random) {
					resultSpan.innerHTML = "猜小了";
				} else{
					resultSpan.innerHTML = "猜对了";
				}
				
			}
		</script>
	</body>
</html>
